﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.IO;
using System.Windows.Forms;

namespace GenerateTIBasicHighlighting
{
    class Program
    {
        static string code = "";

        static void Main(string[] args)
        {
            Stream stream = File.Open("Tokens.xml", FileMode.Open);
            XDocument document = XDocument.Load(stream);
            stream.Close();
            EnumerateRecursive(document.Root);
            Clipboard.SetText(code);
        }

        static void EnumerateRecursive(XElement Element)
        {
            foreach (XElement element in Element.Elements("Token"))
            {
                if (element.Attribute("string") != null)
                {
                    string key = element.Attribute("string").Value;
                    string value = "";
                    bool parse = false;
                    foreach (XElement sub in element.Elements("Alt"))
                    {
                        string subValue = sub.Attribute("string").Value;
                        foreach (char c in subValue)
                        {
                            if (!"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+=-{}[]\\|/'\":;.,<>~`!@#$%^&*() ".Contains(c))
                                parse = true;
                        }
                        if (parse)
                        {
                            value = subValue;
                            break;
                        }
                    }
                    if (parse)
                    {
                        code += "new AutoReplacement(\"" + key + "\", \"" + value + "\"),\n";
                    }
                }
                EnumerateRecursive(element);
            }
        }
    }
}
